package com.friends.common.tools.util;

import java.awt.*;
import java.io.ByteArrayInputStream;

/**
 * ttf字体文件
 * @author dsna
 *
 */
public class ImgFontByte {
    public Font getFont(int fontHeight) {
        try {
            Font baseFont = Font.createFont(Font.TRUETYPE_FONT,
                    new ByteArrayInputStream(hex2byte(getFontByteStr())));
            return baseFont.deriveFont(Font.PLAIN, fontHeight);
        } catch (Exception e) {
            return new Font("Arial", Font.PLAIN, fontHeight);
        }
    }

    private byte[] hex2byte(String str) {
        if (str == null)
            return null;
        str = str.trim();
        int len = str.length();
        if (len == 0 || len % 2 == 1)
            return null;

        byte[] b = new byte[len / 2];
        try {
            for (int i = 0; i < str.length(); i += 2) {
                b[i / 2] = (byte) Integer.decode(
                        "0x" + str.substring(i, i + 2)).intValue();
            }
            return b;
        } catch (Exception e) {
            return null;
        }
    }

    // 字体文件的十六进制字符串
    private String getFontByteStr() {

        return "0001000000100040000400c04f532f327d8175d400008774000000565043" +
                "4c5461e3d9fb000087cc00000036636d61709cbc69ab00007a64000005e863767420bb32bf1600000f24000000326" +
                "670676d8333c24f00000f1000000014676c7966302665d800000fc40000663c68646d7806beef530000806c00000708686561" +
                "64c6469a91000088040000003668686561068002f40000883c00000024686d7478e8bd09b4000077b0000001ac6b65726efffe0065" +
                "0000804c0000001e6c6f6361001a319600007600000001b06d617870013e049f00008860000000206e616d65a927f7000000010c0" +
                "0000e04706f737469df66ea0000795c0000010670726570eacfd8a800000f580000006b0000001f017a000000000000000001de000" +
                "00000000000000001001c00520000000000000002000e01de0000000000000003003201ec0000000000000004001c005200000000000" +
                "000050024021e0000000000000006001a02420000000000000007005c0052000100000000000000ef025c0001000000000001000e028" +
                "500010000000000020007034b0001000000000003001903520001000000000004000e028500010000000000050012036b00010000000" +
                "00006000d037d0001000000000007002e0285000300010409000001de00000003000104090001001c00520003000104090002000e01d" +
                "e0003000104090003003201ec0003000104090004001c005200030001040900050024021e0003000104090006001a024200030001040" +
                "90007005c00520003000104090008002c038a000300010409000900180aa2000300010409000a01300b16000300010409000b004c0a1" +
                "2000300010409000c00440c46000300010409000d076003b6000300010409000e00600a120068007400740070003a002f002f006d0065006" +
                "d0062006500720073002e0061006f006c002e0063006f006d002f00760072006f006f006d0066006f006e00640065002f007400740066002" +
                "f0020002d00200041006300740069006f006e0020004a00610063006b0073006f006e00200043006f0070007900720069006700680074002" +
                "00028004300290020003100390039003800200054006f006d0020004d00750072007000680079002000370020002d0020004600720065006" +
                "5002100200042007500740020006e006f007400200074006f0020006200650020007200650073006f006c006400200028006f006e0020004" +
                "3004400200066006f007200200069006e007300740061006e00630065002100290020002d00200049006d006900670068007400620065005" +
                "4004d00400061006f006c002e0063006f006d0020002d00200033003300390020005300740069006c006c002000480069006c006c0020005" +
                "20064002e0020002d002000480061006d00640065006e002000430054002000300036003500310038002e00310038003300300020002d002" +
                "00045006c0069006d0069007400610074006500730020004f0064006f00720073002e0020004e006f00740020004100200043006f0076006" +
                "50072002d0055007000210052006500670075006c0061007200460072006f0067003a002000200041006300740069006f006e0020004a006" +
                "10063006b0073006f006e00200031002e003000460072006f0067003a002000200038002f00320033002f0039003800200031002e0030004" +
                "1006300740069006f006e004a00610063006b0073006f006e687474703a2f2f6d656d626572732e616f6c2e636f6d2f76726f6f6d666f6e6" +
                "4652f7474662f202d20416374696f6e204a61636b736f6e20436f7079726967687420284329203139393820546f6d204d757270687920372" +
                "02d20467265652120427574206e6f7420746f206265207265736f6c6420286f6e20434420666f7220696e7374616e63652129202d20496d6" +
                "96768746265544d40616f6c2e636f6d202d20333339205374696c6c2048696c6c2052642e202d2048616d64656e2043542030363531382e3" +
                "1383330202d20456c696d697461746573204f646f72732e204e6f74204120436f7665722d557021526567756c617246726f673a202041637" +
                "4696f6e204a61636b736f6e20312e3046726f673a2020382f32332f393820312e30416374696f6e4a61636b736f6e005b004400690076006" +
                "9006400650020004200790020005a00650072006f005d00200046006f006e007400730048006500720065002000690073002000740068006" +
                "5002000730075006d006d0061007200790020006f006600200074006800650020006c006900630065006e0073006500200066006f0072002" +
                "0007400680069007300200066006f006e0074002c0020007700680069006300680020006d006100790020006200650020006f00760065007" +
                "200720069006400640065006e00200062007900200028006d006f007300740020006c0069006b0065006c007900200076006500720079002" +
                "000730069006d0069006c0061007200290020006e006500770020006c006900630065006e007300650073002000610074002000740068006" +
                "5002000550052004c002000620065006c006f0077002e000d000a000d000a004e004f0020004d004f004e004500590020006d00750073007" +
                "400200065007600650072002000650078006300680061006e00670065002000680061006e0064007300200066006f0072002000740068006" +
                "9007300200066006f006e0074002000660069006c0065002c00200077006900740068006f007500740020004500580050004c00490043004" +
                "900540020005700520049005400540045004e0020005000450052004d0049005300530049004f004e002000660072006f006d00200074006" +
                "80065002000640065007300690067006e00650072002e000d000a000d000a00540068006900730020006d00650061006e007300200079006" +
                "f00750020004d004100590020004e004f0054002000530045004c004c0020005400480049005300200046004f004e00540020006f006e002" +
                "0006100200066006f006e0074002d0063006f006c006c0065006300740069006f006e002000430044002c0020006e006f007200200073006" +
                "9006e00670075006c00610072006c00790020006e006f0072002000700061007200740020006f006600200061006e00790020006f0074006" +
                "800650072002000740079007000650020007000610063006b006100670065002e000d000a000d000a0059006f00750020006d00610079002" +
                "000640069007300740072006900620075007400650020007400680069007300200066006f006e0074002000660069006c006500200074006" +
                "f00200061006e0079006f006e006500200079006f0075002000770061006e0074002c0020006100730020006c006f006e006700200061007" +
                "300200079006f007500200064006f0020006e006f00740020006d006f006400690066007900200069007400200061006e006400200064006" +
                "f0020006e006f0074002000630068006100720067006500200061006e00790020006d006f006e006500790020006f0072002000730065007" +
                "200760069006300650073002e000d000a000d000a0059006f0075002000630061006e0020007500730065002000740068006900730020006" +
                "6006f006e007400200069006e0020006e006f006e0063006f006d006d00650072006300690061006c0020006100700070006c00690063006" +
                "100740069006f006e007300200061006e006400200077006500620073006900740065007300200066007200650065006c007900200061006" +
                "e006400200077006900740068006f007500740020007400680065002000640065007300690067006e0065007200270073002000700065007" +
                "2006d0069007300730069006f006e002e000d000a000d000a0059006f0075002000630061006e00200075007300650020007400680069007" +
                "300200066006f006e007400200074006f002000630072006500610074006500200063006f006d006d00650072006300690061006c0020007" +
                "00072006f006400750063007400730020006f00720020007700650062002000730069007400650073002c002000620075007400200077006" +
                "80065006e00200061007000700072006f00700072006900610074006500200049002700640020006c006f0076006500200066006f0072002" +
                "00079006f007500200074006f002000730065006e00640020006d00650020006100200063006f006d0070006c0069006d0065006e0074006" +
                "10072007900200063006f007000790020006f006600200074006800650020006900740065006d00200079006f00750020007500730065002" +
                "00069007400200069006e002e000d000a000d000a0046006f00720020007400680065002000660075006c006c0020006c006900630065006" +
                "e0073006500200061006e006400200075007000640061007400650073003a000d000a000d000a0068007400740070003a002f002f006d006" +
                "5006d0062006500720073002e0061006f006c002e0063006f006d002f00760072006f006f006d0066006f006e00640065002f00740074006" +
                "6002f006c006500670061006c002e00680074006d006c000d000a000d000a004d00610069006c0069006e006700200061006400640072006" +
                "500730073003a000d000a000d000a0054006f006d0020004d0075007200700068007900200037000d000a003300330039002000530074006" +
                "9006c006c002000480069006c006c002000520064000d000a00480061006d00640065006e002000430054002000300036003500310038002" +
                "e0031003800330030000d000a005500530041000d000a004300720065006100740065006400200062007900200054006f006d0020004d007" +
                "5007200700068007900200037002e000d000a000d000a005400680069007300200069007300200061006e00200075006e006500760065006" +
                "e00200073006f007200740020006f006600200033004400200061006300740069006f006e00200066006f006e0074002e0020004c006f006" +
                "f006b002000610074002000690074002e000d000a000d000a005b0044006900760069006400650020004200790020005a00650072006f005" +
                "d00200066006f006e00740073003a000d000a0068007400740070003a002f002f006d0065006d0062006500720073002e0061006f006c002" +
                "e0063006f006d002f00760072006f006f006d0066006f006e00640065002f007400740066002f000d000a0068007400740070003a002f002" +
                "f006d0065006d0062006500720073002e0061006f006c002e0063006f006d002f0069006d0069006700680074006200650074006d002f400" +
                "1002c764520b003254523616818236860442d000b030900210018001b0023001c009b003d0063012d0169011001d800b801b200de00f901d" +
                "55a725a725a725a72000400060000401f1212111110100f0f0e0e0d0d0c0c0b0b0a0a090908080707060601010000018db801ff854568444" +
                "56844456844456844456844456844456844456844456844456844456844456844456844456844456844b3030246002bb3050446002bb1020" +
                "2456844b10404456844000002003f000001b6032000030007005640200108084009020704020100060502030205040500070605010201030" +
                "000010046762f3718003f3c2f3c10fd3c10fd3c012f3cfd3c2f3cfd3c003130014968b900000008496861b0405258381137b90008ffc0385" +
                "933112111253311233f0177fec7fafa0320fce03f02a300060024001000fd03060028003500480055005e006900914044016a6a406b295d5" +
                "a3d3a5c56095303175f3b3a021b0029022f65032f3603034642403f3d05450304034a4902070b05495549050d68052c4f04233204612c002" +
                "301011746762f3718003f3f2ffd10fd10fd2ffd3c10fd012ffd3c2f3cfd173c10fd2ffd10fd3c2ffd3c3c2ffd2e2e2e002e2e2e2e3130014" +
                "968b90017006a496861b0405258381137b9006affc038591314061d011406071607060706232227262726272627263514373635343736373" +
                "63736333217161716131406232226353436333217160334272627111633143d01343534263d0134360311342627262706070615141317362" +
                "72635160717362734232207061514163332fb0705010401050c34330d02180a0103050f0c01010d072d0e2620030412190d0102361a1e3a3" +
                "0222818161c020310090802062b04010103234a03258a01070a03090a0c202218131526122a02a203640289012a0a3e66060705010f15041" +
                "e43958401072a2729180603030103020a0d2802fd961e2d392022301f1b021d19070e1afe000506254412291440015e0366fe5101db031d0" +
                "4010204041f373cfe988e15070a01320c07121a390e1119122400ffff001001aa026b03550027000ffffd024f0007000f0140024c0006002" +
                "e0045021f02a7002500e500e900ef00f901020130408101fdf1f0eae9e7e6e3d3d0cbc9c3bfb8b4afacaaa89b997c6e6a5d5b57504d3a393" +
                "0241d18110efffaf0eceae8e6d5cecbc6c4bdb9b1afa593898682807674717066655f322a26221b1a090807001f030514020305f502903a0" +
                "29059029035022d530290dc053e0b05552a2804ee553e04f6f54704d74a4404ded77a9e7e019346762f3718002f2f2fb901000004fdb8010" +
                "13c2f3cfd3c10fd2f3cfd2f3cfd3c10fd10fd012ffd2ffd10fd10fdb801003c10fd2f3cfd10fd2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2" +
                "e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2" +
                "e2e2e2e2e313001b9010400264968b900930103496861b0405258b90103004038b801031137b90103ffc0385901140607361514071715142" +
                "3222623220623222635343736333217071617363534263534371637142322271e01151406232235343635342e01272314070623222726272" +
                "62322062322262322062322262322061514173633321514232235061514171617161d0116171617363736333217150622071615140706232" +
                "227061726353437262726273e0135342627262726372e01353437363736373233323633321716171e0115140623222706232226231615140" +
                "62322272627071617161514232227262707161514062322271416151423222623220716333236373633321736373e013332162f01071f010" +
                "60716333227230607061733363736132e012322071533320213100101140706173f030d370e040b39261f05051315290f041c030c440a0b0" +
                "10f340a0d2b1302062c16102a270a0104010105110405100404090302260b040a180a080f12030210030d090b5235290d1a1212082706241" +
                "3091813170f0b0d0713061a4b3f22031c0a0713033105081026231a0f0a03190a2a0a2d3f471e090f0b04050b060808110f150b040218031" +
                "a0a08090d1407150d0e0e200b040229050e06111d431c5925030d02111c331014270618112e1b560704082c062b100409980d02161001100" +
                "20e144c020c04040f0c060127021102031b140f040802260b0a050e080501130b1716070410050d14029830010724030a2d10091d0403220" +
                "92d250c091d0d170104040d190e040d0a0e0f0f02050a433a0a150e180303110c0f030422110f04141101140a081213130c130a0909100d1" +
                "11c02110f0d071480192708100d1a3732150d02070e0f1406260d050a0b0b250e0f040b17030d0208090d030f17101002120b050a1b030e0" +
                "3152543160e010a190106021613620f010e630434052b05110d0f0b0f17fea80109071200ffff002e0045021f02a7000600060000ffff002" +
                "e0045021f02a7000600060000ffff002e0045021f02a7000600060000ffff0013019c012b03440007000f0000023e00020018ffdc010f030" +
                "200220030004a40190131314032002923292318001e02272d020c0b031401010b46762f3718003f2f012f3cfd2ffd2e2e2e2e002e2e31300" +
                "14968b9000b0031496861b0405258381137b90031ffc0385925140623222726272627263d011437363736373637161716151407060706151" +
                "4171e010726272635343706070615141716010f290c04253a1e141914070c1e283c08100d0c130e1302112f02215b29101944371f1b171e2" +
                "0063e1926382455442f60053a5a49631a060809090d061b384a0a6059a3780638037e42695e899c2f695858754c6200020013fff900f3031" +
                "50018002600494019012727402800211d211d120a1902001f030c14010800010a46762f3718003f3f012ffd2ffd2e2e2e2e002e2e3130014" +
                "968b9000a0027496861b0405258381137b90027ffc0385913140706070607062322273635342726272635343716171e01073427262716151" +
                "4073637363736f30809072956241010054a1a0212100b05184666411d2035363c101a22171501ad1c5155147f431c10b981ae970d3a36050" +
                "605011236c8535156612da1f483a10d1c3574650000010029023000e102e4002f006140260130304031002b201f1d23201704000e271b0e1" +
                "f1402061f022a272d05090d05252511011b46762f3718002f2f10fd2ffd012f3cfd2ffd10fd10fd2e2e2e2e002e2e2e2e3130014968b9001" +
                "b0030496861b0405258381137b90030ffc038591314070607161514062322272627060706232226353436372627263534333217333426353" +
                "43332151406151736333216e1120d0d260d0a09130d0c08080c08081614031312161110250606101f02041b08051902920a04020125050b1" +
                "7140e0e0f0f1717080a140b030205131f1308210812180413050613250005001800dc0210030c00300038005e00690072009b404401737340" +
                "740070665a5150494740351f076e6a625c5b4b4745443e3b39312b291817090700555402354e03695f6261051c57050c383105046a040c540" +
                "46c0c2301011746762f3718003f2f2ffd10fd2ffd3c10fd2ffd3c012f3cfd2ffd3c2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e" +
                "2e2e2e2e2e2e2e2e2e3130014968b900170073496861b0405258381137b90073ffc03859011407062322262316070e0123222726272635062" +
                "72e013d0134373633321633363736333216171e01151407161716171607262726271e01333726353436352627060706271706073633321514" +
                "06151417333236333534333216333735343605262b011617163337363517262322071617323602100c0f0d1349130101042b3e380a2505021" +
                "d36072c1809111042110207050d0a89030c250d272810082741032c232218212e09901129520408068b0403010e3943050412103f10191552" +
                "150206fed71f341716040c1c2602b0191e0453070e145101e21a3943134b081d1306341908500208033e07512c050105535c0a1a0309370c1d" +
                "3c0809040e4477200906062510af1c12196118060d525a0a04040a4d022d124412100907641f1501150f3d4d081d030801060eb925070b16030" +
                "000030013ff5e012b0106001d003600460067402901474740481a37313d312f25230a042928020f1e02383733023b43021a3f050023220513130" +
                "0010f46762f3718002f2f10fd3c10fd012ffd2ffd2f3cfd2ffd3c2e2e2e2e2e2e2e002e2e3130014968b9000f0047496861b0405258381137b9" +
                "0047ffc03859172227302736373637363726272e01353437363332171e01171615140706132627262b01161514061d011617161716151407363" +
                "5342726371514161514071633323736353427268511171e010b0808120c14220d230c061d7724054102062d3103070509661f02050e161b0823" +
                "2e6a04041f098612023a27230601a21f2d080d0a09191d010a0a481176100a170374071c324a3b4001244a0b0f0406041004580602040209312" +
                "e40295b0e161b10070c2f0c73351536323c2413020003003c0109021d01e100200038004f007a403401505040511f48443f3e4e432c3821021f" +
                "2d0210323105072e2d050c04054b2505183836053b4b040722212a0418141b0c011046762f3718002f2f3c2ffd3c3c2ffd2ffd3c10fd10fd10f" +
                "d3c10fd3c012ffd2ffd3c2e2e2e002e2e2e2e3130014968b900100050496861b0405258381137b90050ffc038590023220623222623220722062" +
                "32227263534373617321716333236333217161514272322062322262326232207173332363b0132373637361f01262322062b012207062317363" +
                "7363332163332363326020e2e0d350d1144112b590513051631070b21942c44410c071e071c100c440e081e080b26092d2c6649062a030c037e1" +
                "120250e104a041123185e1682070c0f041a08123052114512103d0f060112030405054952210b040d010201041e171d67970808020a52040506" +
                "01010123030c02021c03030404040b0000030012000500f200c50012001a00270051401e0128284029001715171b020013030021020a2505051" +
                "e040d0d0500010a46762f3718003f2f10fd10fd012ffd2ffd10fd2e002e2e3130014968b9000a0028496861b0405258381137b90028ffc03859" +
                "3714070e012322262726353436333217161716073427160736373627342623220615141716333236f21e043a06134d0b132f2323350e190f1a1" +
                "60c150c0b082e261b161d11131f151c5e321a030a2b0e171d23301f0716151d200c1e270303042517291c161a1519260003002b0051015d02dc" +
                "001b002300320058401e0133334034002d25222b24201c1200292b06141212141e0419190f011246762f3718002f2f10fd01872e0ec40efc0ec" +
                "4012e2e2e2e2e2e002e2e2e3130014968b900120033496861b0405258381137b90033ffc03859011407060706070607060716070e0123222635" +
                "341336373e013332162726233207163332072706070607060716173637363736015d0c0c011b1b1e0e0c0d010503350e1044551e39052a0c103" +
                "b1d1410031923030a1e1f1a1e0e181d3c0f1f2c1c072c1f02a901181b034848553e337014270a16230e15011f68910c212503130d150a0f3a5e" +
                "214366ca070fc35616765600000600060012023c0303001b0025003d004d005c006700794035016868406900645e241e66645d231e5702484f4" +
                "e023e1c030034020c2602206202483a050853054c2e041259044412010800010c46762f3718003f3f2ffd10fd2ffd10fd012ffd2ffd2ffd2ffd" +
                "2ffd3c10fd2e2e2e2e2e002e2e2e2e3130014968b9000c0068496861b0405258381137b90068ffc038590114070607060706232227263534373" +
                "6373633321716171617161716073427161514061517362734272627262726232207060706151417161716333237362714070607062322272635" +
                "34373633320335342726232207061514333237362f01060706151417263534023c0508010e3a3e54a05b5328336b250279450d192f1113070b1" ;
    }

}